#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e5+10;

struct node{
	int sum,lsum,rsum;
	node(){sum = lsum = rsum = 0;}
	friend node operator + (node x,node y){
		node t;
		t.sum = x.sum + y.sum; t.lsum = max(x.lsum,x.sum + y.lsum); t.rsum = max(y.rsum,y.sum + x.rsum);
		return t;
	}
}t[N<<5];

int rt[N],ans,a[N],n,nodenum,ls[N<<5],rs[N<<5],q[4],id[N];

bool cmp(int x,int y){return a[x] < a[y];}

void build(int &o,int l = 1,int r = n){
	o = ++nodenum; t[o].sum = t[o].lsum = t[o].rsum = r - l + 1; int mid = l+r>>1; if(l == r) return;
	build(ls[o],l,mid); build(rs[o],mid+1,r);
}

void update(int &y,int x,int pos,int v,int l = 1,int r = n){
	y = ++nodenum; ls[y] = ls[x]; rs[y] = rs[x];
	if(l == r){t[y].sum = t[y].lsum = t[y].rsum = v; return;}
	int mid = l+r>>1;
	if(pos <= mid) update(ls[y],ls[x],pos,v,l,mid);
	else update(rs[y],rs[x],pos,v,mid+1,r);
	t[y] = t[ls[y]] + t[rs[y]];
}

node query(int y,int xl,int xr,int l = 1,int r = n){
	if(xl == l && xr == r) return t[y];
	int mid = l+r>>1;
	if(xr <= mid) return query(ls[y],xl,xr,l,mid);
	else if(xl > mid) return query(rs[y],xl,xr,mid+1,r);
	else return query(ls[y],xl,mid,l,mid) + query(rs[y],mid+1,xr,mid+1,r);
}

bool check(int x){
	int tot = 0; 
	if(q[1] + 1 <= q[2] - 1) tot += query(rt[x],q[1]+1,q[2]-1).sum;
	tot += query(rt[x],q[0],q[1]).rsum + query(rt[x],q[2],q[3]).lsum;
	return tot >= 0;
}

void solve(){
	for(int i = 0;i < 4;i++) q[i] = (in + ans) % n + 1; sort(q,q+4);
	ans = 0; int l = 1,r = n;
	while(l <= r){
		int mid = l+r>>1;
		if(check(mid)) ans = max(ans,a[id[mid]]),l = mid+1;
		else r = mid-1;
	}printf("%d\n",ans);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	for(int i = 1;i <= n;i++) a[i] = in,id[i] = i;
	sort(id+1,id+n+1,cmp);
	build(rt[1]); for(int i = 2;i <= n;i++) update(rt[i],rt[i-1],id[i-1],-1);
	int q = in;
	while(q--) solve();
	return 0;
}
